package com.ruoyi.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.google.gson.JsonObject;

import java.io.IOException;

public class GsonJsonObjectSerializer extends JsonSerializer<JsonObject> {
    @Override
    public void serialize(JsonObject value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null || value.isJsonNull()) {
            gen.writeNull();
        } else {
            // 直接将 JsonObject 转换为 JSON 字符串
            gen.writeRawValue(value.toString());
        }
    }
}
